<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <#include "/common/plateform/include/common-base.ftl">
  <title>动态数据表对象ius接口选择器</title>
</head>

<style>

.content-wrapper {
  margin-left: 0px;
}
</style>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

  <!-- Main start -->
  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
      <div class="row">
        <div class="col-xs-12 ibox">
        
          <!--搜索  start -->
          <div class="box box-info">

             <!--搜索title  start -->

            <!--搜索title  end -->
            <div class="box-body">
			  <form id="searchForm" class="form-horizontal" action="javascript:;">
				  <input type="hidden" name="pageName" value="objName-table"/>
				  <input type="hidden" name="formName" value="searchForm"/>
				  <input type="hidden" name="orderBy" value="sortInfo.info_table_name asc"/>
				<div class="form-group">
				
					<div class="col-sm-1  text-right"><label class="control-label" >中文名：</label></div>
					<div class="col-sm-2">
						 <input type="text" class="form-control clean"  name="sortInfo.wl_sortName" value=""/>
					</div>
					
					<div class="col-sm-1  text-right"><label class="control-label" >英文名：</label></div>
					<div class="col-sm-2">
						 <input type="text" class="form-control clean"  name="sortInfo.wl_infoTableName" value=""/>
					</div>
					
					<div class="col-sm-1  text-right"><label class="control-label" >对象名：</label></div>
					<div class="col-sm-2">
						 <input type="text" class="form-control clean"  name="sortInfo.wi_objName" value="${objNameStr!''}"/>
					</div>

					<div class="col-sm-1  text-right"><label class="control-label" >系统：</label></div>
					<div class="col-sm-2">
						<input type="text" class="form-control"  name="sortInfo.w_sysName" value="${sysEname!''}"/>
					</div>
				</div>
				  <div class="form-group">
					<div class="col-sm-12 text-center">
						 <button type="button" class="btn btn-success" onclick="getTableData();"><i class="fa fa-search"></i> 查询</button>&nbsp;&nbsp;
				      	 <button type="button" class="btn btn-warning" onclick="restSearchForm()">重置 </button>&nbsp;&nbsp;
				      	 <button type="button" class="btn btn-danger" onclick="checkedSaveOk()"><i class="fa fa-check-square-o"></i> 选择完成 </button>
					</div>
					
				</div>
				
			  </form>
            </div>
	     </div>	
	     <!-- 搜索 end -->
        
        <div class="box box-success">
            <!--列表title  start --> 
	        <div class="box-header with-border">
                <div id="checked_obj_div"></div>
            </div>
            
            <!-- /.box-header -->
            <div class="box-body">
              <table id="dataList2" class="table table-bordered" >
                <thead class="bg-success">
				<tr>
					<th rowspan="2" class="text-center" style="vertical-align:middle;width:200px;">数据表名</th>
					<th rowspan="2" class="text-center" style="vertical-align:middle;width:200px;">数据表对象名</th>
					<th colspan="4" class="text-center">单一操作接口（CRUD）</th>
					<th colspan="2" class="text-center">批量操作接口</th>
				</tr>
				<tr>
					<th class="text-center">新增（C）</th>
					<th class="text-center">查询（R）</th>
					<th class="text-center">修改（U）</th>
					<th class="text-center">删除（D）</th>
					<th class="text-center">新增（C-Batch）</th>
					<th class="text-center">修改（U-Batch）</th>
				</tr>
                </thead>
                <tbody id="dataList-body">
                </tbody>
              </table>
              <center>
    	  		<ul id="dataList-page"></ul>
              </center>
            </div>
            
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
    
 <script type="text/template" id="dataList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
			<tr>
				<td><?=(pageObj.currentPage-1)*10+(i+1)?>.<?=strUtil.doNull(rows[i].sortInfo.sortName,'')?></td>
				<td><?=strUtil.doNull(rows[i].sortInfo.objName,'')?></td>
				<td class="text-center"><input type="checkbox" table-name="<?=rows[i].sortInfo.infoTableName?>" sort-code="<?=rows[i].sortInfo.sortCode?>" batch-flag="F" form-name="addForm" obj-name="i_<?=rows[i].sortInfo.objName?>" onclick="getChecked(this)"/></td>
				<td class="text-center"><input type="checkbox" table-name="<?=rows[i].sortInfo.infoTableName?>" sort-code="<?=rows[i].sortInfo.sortCode?>" batch-flag="F" form-name="searchForm" obj-name="s_<?=rows[i].sortInfo.objName?>" onclick="getChecked(this)"/></td>
				<td class="text-center"><input type="checkbox" table-name="<?=rows[i].sortInfo.infoTableName?>" sort-code="<?=rows[i].sortInfo.sortCode?>" batch-flag="F" form-name="editForm" obj-name="u_<?=rows[i].sortInfo.objName?>" onclick="getChecked(this)"/></td>
				<td class="text-center"><input type="checkbox" table-name="<?=rows[i].sortInfo.infoTableName?>" sort-code="<?=rows[i].sortInfo.sortCode?>" batch-flag="F" form-name="delForm" obj-name="d_<?=rows[i].sortInfo.objName?>" onclick="getChecked(this)"/></td>
				<td class="text-center"><input type="checkbox" table-name="<?=rows[i].sortInfo.infoTableName?>" sort-code="<?=rows[i].sortInfo.sortCode?>" batch-flag="T" form-name="addFormBatch" obj-name="ib_<?=rows[i].sortInfo.objName?>" onclick="getChecked(this)"/></td>
				<td class="text-center"><input type="checkbox" table-name="<?=rows[i].sortInfo.infoTableName?>" sort-code="<?=rows[i].sortInfo.sortCode?>" batch-flag="T" form-name="editFormBatch" obj-name="ub_<?=rows[i].sortInfo.objName?>" onclick="getChecked(this)"/></td>
			</tr>
		<?}?>
</script>

<script>
var clickMenu = "objName-table";
var id,myPage,dataListId,searchFormId,isShowLog,objName,objId;
myPage = 20;
dataListId = "dataList";
searchFormId = "searchForm";
objName = "pubMetadata";
objId = "infoId";
isShowLog = true;
var id;
var objNameStr="${objNameStr!''}";
$(function () {
	//1、加载分页列表数据
	getTableData();
	//2、控制是否启用token
	//setToken();
	id = $('tr.selected th').eq(0).html();
	//请在下面补充其他初始化方法（如数据字典、页面加载数据等）
	DictUtil.getDictExtList("#proUnit", dictUrl, {cateEname:"productUnit"});
	DictUtil.getDataToSelect("#selectCate",{modelTypes:"s_trpCate"},{value:"cateId",text:"cateName",other:"cateNo,cateType"});
	
 });


function setInfoTableName(formId){
	var sysCode = $("#"+formId+" #tablePrefix").val();
	var sortCode = $("#"+formId+" #sortCode").val();
	var tableName = sysCode+"_"+sortCode;
	$("#"+formId+" #infoTableName").val(tableName);
	$("#"+formId+" #objName").val(sysCode+tranformStr1(sortCode));
}
//字符串转成驼峰的方法
function transformStr3(str){
    var re=/_(\w)/g;
    return str.replace(re,function ($0,$1){
        return $1.toUpperCase();
    });
}

//首字母大写
function tranformStr1(str){
    var strArr=transformStr3(str);
    strArr=strArr.charAt(0).toUpperCase()+strArr.substring(1);
    return strArr;
}
//重置查询，同时清空之前选中项和内容。
function restSearchForm(){
	mytools.cleanData("#searchForm");
	$("#checked_obj_div").html("");
	$("#"+dataListId+"-body").find("tr td").find("input[type='checkbox']").each(function(){
		$(this).prop("checked",false);
		$(this).parent().removeClass("bg-danger");
	});
}
$(function () {
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected td').eq(0).html();
	   //  console.log($('tr.selected td').eq(1).html())
	} );
	
	
  });
//加载列表数据
function getTableData(){
	deleteAllRow(dataListId);
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFormId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFormId).serialize(),myPage),
		   dataType:'json',
		   success: function(myData){
			var data = baidu.template(dataListId+"-template",eval(myData));  
			$("#"+dataListId+"-body").html(data);
			  var option= {
					   ele:$("#"+dataListId+"-page")[0],
					   total:myData.total,
					   fn:getTableData,
					   url:common_list_url+"?"+$("#"+searchFormId).serialize()
				   }
				generatePages(option);
			  
			  checkedObjTr();
		   }
	
		});	
  }



function checkedObjTr(){
	if(!strUtil.isNull(objNameStr)){
		var objNameArrays = objNameStr.split(",");
		var objNameMap = {};
		for(var i=0;i<objNameArrays.length;i++){
			var key = objNameArrays[i];
			objNameMap[key]=key;
		}
		$("#"+dataListId+"-body").find("tr td").find("input[type='checkbox']").each(function(){
			if(objNameMap[$(this).attr("obj-name")]){
				$(this).click();//触发checkbox的onclick点击事件
			}
		});
	}
}

function refresh(){
	getTableData();
}


function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			 $('#formToken').val(myData);
	  	}
	});	
}

//勾选对象
function getChecked(obj){
	var objName = $(obj).attr("obj-name");
	var batchFlag = $(obj).attr("batch-flag");
    var formName = $(obj).attr("form-name");
    var tableName = $(obj).attr("table-name");
    var sortCode= $(obj).attr("sort-code")
    $(obj).parent().addClass("bg-danger");
    if($(obj).is(':checked')){
        var divHtml = " <button type=\"button\" id='btn-"+objName+"' table-name='"+tableName+"' sort-code='"+sortCode+"' batch-flag='"+batchFlag+"' obj-name=\""+objName+"\" form-name='"+formName+"' class=\"btn btn-danger btn-sm\"> "+objName+"</button> ";
        $("#checked_obj_div").append(divHtml);
    }else{
        $("#checked_obj_div").find("#btn-"+objName).remove();
        $(obj).parent().removeClass("bg-danger");
    }

}
//选择完成后，保存对象
function checkedSaveOk(){
	var btnMap = {};
	$("#checked_obj_div").find("button").each(function(){
		var tableObjName = $(this).attr("obj-name");
        var batchFlag = $(this).attr("batch-flag");
        var formName = $(this).attr("form-name");
        var tableName = $(this).attr("table-name");
        var sortCode = $(this).attr("sort-code");
		btnMap[tableObjName] = eval({"tableName":tableName,"tableObjName":tableObjName,"batchFlag":batchFlag,"formName":formName,"sortCode":sortCode});
	});
	var len  = Object.keys(btnMap).length;
	if(len<1){
		layer.alert("请至少选中一个表对象操作接口！");
		return;
	}
	parent.preObjTableCallBack(btnMap);
}
</script>   
    
  </div>
  <!-- /.content-wrapper -->
</div>  

</body>
	


</html>

